<?php

namespace common\models\user;

use Yii;

/**
 * This is the model class for table "{{%user_follow}}".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $model 关注模型
 * @property int $model_id 被关注模型主键
 * @property string $remark 备注名称
 * @property int $listorder 显示顺序
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class UserFollow extends \common\base\ActiveRecord {

    use \common\traits\Constants;
    use \common\traits\TimestampBehavior;
    use \common\traits\QueryInstanceActiveRecord;

    const MODEL_TEACHER = 'teacher';
    const MODEL_SCHOOL = 'school';

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%user_follow}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'model_id', 'listorder', 'created_at', 'updated_at'], 'integer'],
            [['model', 'remark'], 'string', 'max' => 50],
            [['user_id', 'model', 'model_id'], 'unique', 'targetAttribute' => ['user_id', 'model', 'model_id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => '用户ID',
            'model' => '关注模型',
            'model_id' => '被关注模型主键',
            'remark' => '备注名称',
            'listorder' => '显示顺序',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    public function getTeacher() {
        return $this->hasOne(\common\models\teacher\Teacher::className(), ['id' => 'model_id']);
    }

    public function getSchool() {
        return $this->hasOne(\common\models\school\School::className(), ['id' => 'model_id']);
    }

}
